//
//  HLENetWorkCache.h
//  HLENetwork_Example
//
//  Created by hle1879 on 2020/9/28.
//  Copyright © 2020 13434436448@163.com. All rights reserved.
//

#import <Foundation/Foundation.h>

@class HLEBaseRequest;
@class HLENetWorkConfig;

NS_ASSUME_NONNULL_BEGIN

@interface HLENetWorkCache : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

///通过缓存的路径来创建
+ (void)initWithCachePath:(NSString*)cachePath;

///通过配置来创建
+ (void)initWithConfig:(HLENetWorkConfig*)config;

///缓存网络数据
+ (void)setCacheWithRequest:(HLEBaseRequest*)request cacheData:(id _Nullable)cacheData validTime:(NSTimeInterval)validTime;

///缓存网络数据 (缓存数据量大时缓存会占用线程直到移除结束)
+ (void)setCacheWithRequest:(HLEBaseRequest*)request cacheData:(id _Nullable)cacheData validTime:(NSTimeInterval)validTime completion:(void(^)(void))completion;


///获取指定网络请求的缓存数据
+ (id)getCacheWithRequest:(HLEBaseRequest*)request validTime:(NSTimeInterval)validTime;

///获取指定网络请求的缓存数据 (缓存数据量大时缓存会占用线程直到移除结束)
+ (void)getCacheWithRequest:(HLEBaseRequest*)request validTime:(NSTimeInterval)validTime completion:(void(^)(NSString * _Nonnull, id<NSCoding>  _Nullable))completion;
                                         

///移除指定网络请求的数据缓存
+ (void)removeCacheWithRequest:(HLEBaseRequest*)request;

///移除指定网络请求的数据缓存带结果回调 (缓存数据量大时移除缓存会占用线程直到移除结束)
+ (void)removeCacheWithRequest:(HLEBaseRequest*)request completion:(void(^)(NSString * _Nonnull))completion;

/// 移除所有网络请求数据缓存
+ (void)removeAllCache;

/// 移除所有网络请求数据缓存带结果回调 (缓存数据量大时移除缓存会占用线程直到移除结束)
+ (void)removeAllCacheWithCompletion:(void(^)(void))completion;

/// 获取网络缓存的总大小 （bytes 字节）
+ (NSUInteger)totalCacheSize;

/// 获取网络缓存的总大小  直接返回计算好的B KB MB GB
+ (NSString *)totalCacheSizeDescription;

///============扩展一下，可以让其他的API使用该缓存类============
///通过key设置缓存
+ (void)setCacheWithCacheKey:(NSString*)cacheKey cacheData:(id _Nullable)cacheData validTime:(NSTimeInterval)validTime;

 ///通过key设置缓存(缓存数据量大时缓存会占用线程直到移除结束)
+ (void)setCacheWithCacheKey:(NSString*)cacheKey cacheData:(id _Nullable)cacheData validTime:(NSTimeInterval)validTime completion:(void(^)(void))completion;

///通过key获取缓存
+ (id)getCacheWithCacheKey:(NSString*)cacheKey validTime:(NSTimeInterval)validTime;


///通过key获取缓存 (缓存数据量大时缓存会占用线程直到移除结束)
+ (void)getCacheWithCacheKey:(NSString*)cacheKey validTime:(NSTimeInterval)validTime completion:(void(^)(NSString * _Nonnull, id<NSCoding>  _Nullable))completion;

///移除指定key的数据缓存
+ (void)removeCacheWithCacheKey:(NSString*)cacheKey;

///移除指定key的数据缓存带结果回调 (缓存数据量大时移除缓存会占用线程直到移除结束)
+ (void)removeCacheWithCacheKey:(NSString*)cacheKey completion:(void(^)(NSString * _Nonnull))completion;
@end

NS_ASSUME_NONNULL_END
